
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
	"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<link rel="stylesheet" href="../css/wordcloud.css" type="text/css">
	<title>untitled</title>
	
</head>

<body>
<?php
include '../config/config.php';
include 'Zend/Db.php';
include '../php/wordcloud.class.php';

$db = Zend_Db::factory('Pdo_Mysql', $dbConfig);

$cleaned_text = get_cleaned_text($db);

foreach ($cleaned_text as $key=>$value) {

	$words = explode(' ', $value['cleaned_text']);
	$title = $value['module_title'];
	$word_hash = array_count_values($words);
	unset($word_hash['']);
	asort($word_hash, SORT_NUMERIC);
	// print_r($word_hash);
	// print_r($word_hash);

	$cloud = new wordCloud();

	foreach ($word_hash as $key=>$value) {

		switch ($value)
		{
			case ($value>15 AND $value<=30):
			$size = 1;
			$colour = '#cc0066';
			break;
			
			case ($value>30 AND $value<=45):
			$size = 2;
			$colour = '#336699';
			break;
			
			case ($value>40 AND $value<=55):
			$size = 3;
			$colour = '#993399';
			break;
			
			case ($value>55 AND $value<=75):
			$size = 4;
			$colour = '#cc0033';
			break;
			
			case ($value>75 AND $value<=100):
			$size = 5;
			$colour = '#6633ff';
			break;
			
			case ($value>100 AND $value<=130):
			$size = 6;
			$colour = '#336666';
			break;
			
			case ($value>130 AND $value<=165):
			$size = 7;
			$colour = '#006699';
			break;
			
			case ($value>165 AND $value<=200):
			$size = 8;
			$colour = '#cc0000';
			break;
			
			case ($value>200):
			$size = 9;
			$colour = '#ff0000';
			break;
			
		}

		if ($value > 25) {
			
			// echo $key.'=>'.$value.'<br/>';
			if (preg_match('/[a-zA-Z]/', substr($key, 0, 1))) {
				// $key = strtolower($key);
				// $key = rtrim($key, 'a..z');
				$count = $key.'=>['.$value.']';
				$cloud->addWord(array('word' => "$count", 'size' => "$size", 'colour'=>"$colour")); // Advanced user method
			}
		}

	}
	
	echo "<h3>$title tag cloud as at: dd/mm</h3>";
	
	$myCloud = $cloud->showCloud('array');
	
	asort($myCloud);
	
	// $myCloud = $scloud->showCloud('array');
    
	foreach ($myCloud as $cloudArray) {
        echo ' &nbsp; <span style="color: '.$cloudArray['colour'].';" class="word size'.$cloudArray['range'].'">'.$cloudArray['word'].'</span> &nbsp;';
     }
	
	echo '<hr/>';

}

function get_cleaned_text($db) {	
	
	$query = 'SELECT fk_module_id, module_title, cleaned_text
			  FROM modules, tags_by_module
			  WHERE module_code=fk_module_id';
	
	$result = $db->fetchAll($query);
	
	return $result;	
}


?>

</body>
</html>
